﻿using AutoMapper;
using MediatR;
using S.Authorization.API.Application.Command.Role;
using S.Authorization.Domain.Model.Authority;
using S.Authorization.Infrastructure.Interface.Role;

namespace S.Authorization.API.Application.CommandHandlers.Role
{
    /// <summary>
    /// 角色修改
    /// </summary>
    public class RoleUpdateCommandHandler : IRequestHandler<RoleUpdateCommand, bool>
    {
        #region 注入
        private readonly IRoleRepository repository;
        private readonly IMapper mapper;

        public RoleUpdateCommandHandler(IRoleRepository repository,IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }
        #endregion
        public async Task<bool> Handle(RoleUpdateCommand request, CancellationToken cancellationToken)
        {
            return await repository.UpdateAsync(mapper.Map<RoleModel>(request));
        }
    }
}
